home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_02 / 9n02073a < prev    next >
Text File  |  1990-12-16  |  9KB  |  224 lines

  1.  
  2. /*
  3.  *    10-Oct-1990 - created
  4.  */
  5.  
  6. /***********************************************************
  7.  *
  8.  *    Module:   olist.h
  9.  *
  10.  *    Purpose:  Include file for ordered lists
  11.  *
  12.  *    (c) Copyright 1990 Kenneth L. Grogan Jr.
  13.  *
  14.  **********************************************************/
  15.  
  16.  
  17. #ifndef OLIST_H
  18. #define OLIST_H
  19.  
  20. #ifndef OLIST_X
  21. #define OLIST_X
  22.                                 /* global error variable */
  23. extern int      olist_errno;
  24.  
  25. #endif
  26.  
  27. #define OLIST_SUCCESS           0
  28. #define OLIST_INVALID           1
  29. #define OLIST_NO_MEMORY         2
  30. #define OLIST_EMPTY             3
  31. #define OLIST_INVALID_TYPE      4
  32. #define OLIST_NOT_FOUND         5
  33. #define OLIST_KEY_EXISTS        6
  34. #define OLIST_NO_CURRENT        7
  35. #define OLIST_END_OF_LIST       8
  36.  
  37. #define OLIST_INVALID_STR       "olist is invalid"
  38. #define OLIST_NO_MEMORY_STR     "No more memory"
  39. #define OLIST_EMPTY_STR         "This list is empty"
  40. #define OLIST_INVALID_TYPE_STR  "Key type is invalid"
  41. #define OLIST_NOT_FOUND_STR     "Key was not found"
  42. #define OLIST_KEY_EXISTS_STR    "Key already exists in list"
  43. #define OLIST_NO_CURRENT_STR    "No current node in this list"
  44. #define OLIST_END_OF_LIST_STR   "End of the list"
  45.  
  46.                                 /* olist type */
  47. typedef void    *OLIST;
  48.                                 /* olist key type */
  49. typedef int     OLIST_KEY_T;
  50.  
  51.                                 /* olist key type values */
  52. #define OLIST_KEY_1             0
  53. #define OLIST_KEY_2             1
  54. #define OLIST_KEY_3             2
  55. #define OLIST_NUM_KEY_TYPES     3
  56. #define OLIST_NO_KEY            4
  57.  
  58. #define OLIST_UINT      OLIST_KEY_1
  59. #define OLIST_DBL       OLIST_KEY_2
  60. #define OLIST_PTR       OLIST_KEY_3
  61.                                 /* olist with unsigned keys */
  62. #define olistu_new()            (olist_new(OLIST_UINT, NULL))
  63. #define olistu_kill(ol)         (olist_kill(ol))
  64. #define olistu_size(ol)         (olist_size(ol)
  65. #define olistu_key_type(ol)     (olist_key_type(ol))
  66. #define olistu_insert(ol, inkey, data) \
  67.     (olist_add((ol), OLIST_UINT, &(inkey), (data), FALSE))
  68. #define olistu_replace(ol, inkey, data) \
  69.     (olist_add((ol), OLIST_UINT, &(inkey), (data), TRUE))
  70. #define olistu_remove(ol, inkey) \
  71.     (olist_remove((ol), OLIST_UINT, &(inkey)))
  72. #define olistu_remove_all(ol)   (olist_remove_all(ol))
  73. #define olistu_find(ol, inkey)  (olist_find((ol), \
  74.     OLIST_UINT, &(inkey)))
  75. #define olistu_query(ol, inkey, outkey, before) \
  76.     (olist_query((ol), OLIST_UINT, &(inkey), &(outkey), \
  77.         (before)))
  78. #define olistu_get_last(ol, outkey) \
  79.     (olist_get_last((ol), OLIST_UINT, &(outkey)))
  80. #define olistu_first(ol, outkey) \
  81.     (olist_do_first((ol), OLIST_UINT, &(outkey), TRUE))
  82. #define olistu_get_first(ol, outkey) \
  83.     (olist_do_first((ol), OLIST_UINT, &(outkey), FALSE))
  84. #define olistu_next(ol, outkey) \
  85.     (olist_do_next((ol), OLIST_UINT, &(outkey), TRUE))
  86. #define olistu_get_next(ol, outkey) \
  87.     (olist_do_next((ol), OLIST_UINT, &(outkey), FALSE))
  88. #define olistu_get_current(ol, outkey) \
  89.     (olist_get_current((ol), OLIST_UINT, &(outkey)))
  90. #define olistu_compares(ol, inkey) \
  91.     (olist_compares((ol), OLIST_UINT, &(inkey)))
  92.  
  93.                                 /* olist with double keys */
  94. #define olistd_new()            (olist_new(OLIST_DBL, NULL))
  95. #define olistd_kill(ol)         (olist_kill(ol))
  96. #define olistd_size(ol)         (olist_size(ol)
  97. #define olistd_key_type(ol)     (olist_key_type(ol))
  98. #define olistd_insert(ol, inkey, data) \
  99.     (olist_add((ol), OLIST_DBL, &(inkey), (data), FALSE))
  100. #define olistd_replace(ol, inkey, data) \
  101.     (olist_add((ol), OLIST_DBL, &(inkey), (data), TRUE))
  102. #define olistd_remove(ol, inkey) \
  103.     (olist_remove((ol), OLIST_DBL, &(inkey)))
  104. #define olistd_remove_all(ol)   (olist_remove_all(ol))
  105. #define olistd_find(ol, inkey) \
  106.     (olist_find((ol), OLIST_DBL, &(inkey)))
  107. #define olistd_query(ol, inkey, outkey, before) \
  108.     (olist_query((ol), OLIST_DBL, &(inkey), &(outkey), (before)))
  109. #define olistd_get_last(ol, outkey) \
  110.     (olist_get_last((ol), OLIST_DBL, &(outkey)))
  111. #define olistd_first(ol, outkey) \
  112.     (olist_do_first((ol), OLIST_DBL, &(outkey), TRUE))
  113. #define olistd_get_first(ol, outkey) \
  114.     (olist_do_first((ol), OLIST_DBL, &(outkey), FALSE))
  115. #define olistd_next(ol, outkey) \
  116.     (olist_do_next((ol), OLIST_DBL, &(outkey), TRUE))
  117. #define olistd_get_next(ol, outkey) \
  118.     (olist_do_next((ol), OLIST_DBL, &(outkey), FALSE))
  119. #define olistd_get_current(ol, outkey) \
  120.     (olist_get_current((ol), OLIST_DBL, &(outkey)))
  121. #define olistd_compares(ol, inkey) \
  122.     (olist_compares((ol), OLIST_DBL, &(inkey)))
  123.  
  124.                                 /* olist with pointer keys */
  125. #define olistp_new(comp_func)   (olist_new(OLIST_PTR, comp_func))
  126. #define olistp_kill(ol)         (olist_kill(ol))
  127. #define olistp_size(ol)         (olist_size(ol)
  128. #define olistp_key_type(ol)     (olist_key_type(ol))
  129. #define olistp_insert(ol, inkey, data) \
  130.     (olist_add((ol), OLIST_PTR, &(inkey), (data), FALSE))
  131. #define olistp_replace(ol, inkey, data) \
  132.     (olist_add((ol), OLIST_PTR, &(inkey), (data), TRUE))
  133. #define olistp_remove(ol, inkey) \
  134.     (olist_remove((ol), OLIST_PTR, &(inkey)))
  135. #define olistp_remove_all(ol)   (olist_remove_all(ol))
  136. #define olistp_find(ol, inkey) \
  137.         (olist_find((ol), OLIST_PTR, &(inkey)))
  138. #define olistp_query(ol, inkey, outkey, before) \
  139.     (olist_query((ol), OLIST_PTR, &(inkey), &(outkey), (before)))
  140. #define olistp_get_last(ol, outkey) \
  141.     (olist_get_last((ol), OLIST_PTR, &(outkey)))
  142. #define olistp_first(ol, outkey) \
  143.     (olist_do_first((ol), OLIST_PTR, &(outkey), TRUE))
  144. #define olistp_get_first(ol, outkey) \
  145.     (olist_do_first((ol), OLIST_PTR, &(outkey), FALSE))
  146. #define olistp_next(ol, outkey) \
  147.     (olist_do_next((ol), OLIST_PTR, &(outkey), TRUE))
  148. #define olistp_get_next(ol, outkey) \
  149.     (olist_do_next((ol), OLIST_PTR, &(outkey), FALSE))
  150. #define olistp_get_current(ol, outkey) \
  151.     (olist_get_current((ol), OLIST_PTR, &(outkey)))
  152. #define olistp_compares(ol, inkey) \
  153.     (olist_compares((ol), OLIST_PTR, &(inkey)))
  154.  
  155.                                 /* function prototypes */
  156. #ifdef PROTO
  157.  
  158. OLIST olist_new (OLIST_KEY_T    key_type,
  159.                  int            (*compare_func)());
  160. bool olist_kill (OLIST  o_list);
  161. size_t olist_size (OLIST        o_list);
  162. OLIST_KEY_T olist_key_type (OLIST       o_list);
  163. bool olist_add (OLIST           o_list,
  164.                 OLIST_KEY_T     key_type,
  165.                 void            *inkey,
  166.                 void            *client_data,
  167.                 bool            replace_data);
  168. bool olist_remove (OLIST        o_list,
  169.                    OLIST_KEY_T  key_type,
  170.                    void         *inkey);
  171. bool olist_remove_all (OLIST    o_list);
  172. void *olist_find (OLIST         o_list,
  173.                   OLIST_KEY_T   key_type,
  174.                   void          *inkey);
  175. void *olist_query (OLIST        o_list,
  176.                    OLIST_KEY_T  key_type,
  177.                    void         *inkey,
  178.                    void         *outkey,
  179.                    bool         find_before);
  180. void *olist_get_last (OLIST             o_list,
  181.                       OLIST_KEY_T       key_type,
  182.                       void              *outkey);
  183. void *olist_do_first (OLIST             o_list,
  184.                       OLIST_KEY_T       key_type,
  185.                       void              *outkey,
  186.                       bool              set_current);
  187. void *olist_do_next (OLIST              o_list,
  188.                      OLIST_KEY_T        key_type,
  189.                      void               *outkey,
  190.                      bool               set_current);
  191. void *olist_get_current (OLIST          o_list,
  192.                          OLIST_KEY_T    key_type,
  193.                          void           *outkey);
  194. int olist_compares (OLIST       o_list,
  195.                     OLIST_KEY_T key_type,
  196.                     void        *inkey);
  197. bool olist_report (OLIST        o_list);
  198.  
  199. #else
  200.  
  201. OLIST olist_new ();
  202. bool olist_kill ();
  203. size_t olist_size ();
  204. OLIST_KEY_T olist_key_type ();
  205. bool o